package com.ninth_group.utils;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class ParseLocalTimeUtil {
    // 将 HH:ss 或 H:mm 格式字符串转成 LocalTime
    public static LocalTime parseToLocalTime(String timeStr) {
        if (timeStr == null || timeStr.isBlank()) {
            return null;
        }
        try {
            // 使用格式 "H:mm" 可兼容 "8:00"、"13:18"
            return LocalTime.parse(timeStr, DateTimeFormatter.ofPattern("H:mm"));
        } catch (DateTimeParseException e) {
            throw new IllegalArgumentException("Invalid time format: " + timeStr, e);
        }
    }
}
